const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
module.exports = {
  mode: "none",
  entry: {
    zpAddPackage: "./src/index.js",
    "zpAddPackage.min": "./src/index.js",
  },
  output: {
    filename: "[name].js",
    path: path.resolve(__dirname, "dist"),
    library: "wxhf_add", //导出库的名称
    libraryTarget: "umd", // 以何种方式导出 => 导出default属性
    libraryExport: "default", // 导出哪个属性，只有在libraryTarget设置为commonjs或者commonjs2的时候才有效
  },
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        include: /\.min\.js$/,
      }),
    ],
  },
  plugins: [
    new CleanWebpackPlugin(), //打包自动清空之前打包的文件目录
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            //使用babel-loader将es6转化为es5
            loader: "babel-loader",
            options: {
              presets: ["@babel/preset-env"],
            },
          },
        ],
      },
    ],
  },
};
